package com.sgzn.sgpay.util;

import java.util.Random;

/**
 * Created by xxjs-gd-llf
 * DATETIME:2018/4/23 22:36
 * Description:
 */
public class RandomUtil {


    //随机密码生成
    public static String makeRandomPassword(int len){
        char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*.?".toCharArray();
        StringBuilder sb = new StringBuilder();
        Random r = new Random();
        for (int x = 0; x < len; ++x) {
            sb.append(charr[r.nextInt(charr.length)]);
        }
        return sb.toString();
    }

    /**
     * 生成6位随机整数
     * @param len
     * @return
     */
    public static String generateRandomNumber(int len){
        char charr[] = "0123456789".toCharArray();
        StringBuilder sb = new StringBuilder();
        Random r = new Random();
        for (int x = 0; x < len; ++x) {
            sb.append(charr[r.nextInt(charr.length)]);
        }
        return sb.toString();
    }

    public static void main(String[] args){

        System.out.println(generateRandomNumber(6));
    }


}
